28 #ifndef _spoton_utilities_h_ 29 #define _spoton_utilities_h_ 31 #include <QDesktopWidget> 38 static void centerWidget(QWidget *child, QWidget *parent)
47 #if QT_VERSION >= 0x050000 49 if(X11->isSupportedByWM(ATOM(_NET_WM_FULL_PLACEMENT)))
61 int extraw = 0, extrah = 0, scrn = 0;
64 parent = parent->window();
69 scrn = QApplication::desktop()->screenNumber(parent);
70 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 71 else if(QApplication::desktop()->isVirtualDesktop())
72 scrn = QApplication::desktop()->screenNumber(QCursor::pos());
75 scrn = QApplication::desktop()->screenNumber(child);
77 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 78 desk = QApplication::desktop()->availableGeometry(scrn);
80 desk = QGuiApplication::screens().value(scrn) ?
81 QGuiApplication::screens().value(scrn)->geometry() : QRect();
84 QWidgetList list = QApplication::topLevelWidgets();
86 for(
int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i)
88 QWidget *current = list.at(i);
90 if(current->isVisible())
92 int frameh = current->geometry().y() - current->y();
93 int framew = current->geometry().x() - current->x();
95 extraw = qMax(extraw, framew);
96 extrah = qMax(extrah, frameh);
100 if(extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40)
108 QPoint pp = parent->mapToGlobal(QPoint(0,0));
110 p = QPoint(pp.x() + parent->width() / 2,
111 pp.y() + parent->height() / 2);
114 p = QPoint(desk.x() + desk.width() / 2, desk.y() + desk.height() / 2);
116 p = QPoint(p.x() - child->width() / 2 - extraw,
117 p.y() - child->height() / 2 - extrah);
119 if(p.x() + extraw + child->width() > desk.x() + desk.width())
120 p.setX(desk.x() + desk.width() - child->width() - extraw);
125 if(p.y() + extrah + child->height() > desk.y() + desk.height())
126 p.setY(desk.y() + desk.height() - child->height() - extrah);
Definition: spot-on-utilities.h:35